import tornado.web
import tornado.ioloop
from . import utils
import json
'''
#
#7.3 相似图像IICD
同步
    http://ip:port/pic/iicd
    {
        "id":"1",
        "picUri":"",
        "type":"enroll", #search remove
        "dbName":"iicd_test"
    }
'''
class PicIICD(tornado.web.RequestHandler):

    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data,{
                "id":"1",
                "picUri":"",
                "type":"enroll",
                "dbName":"iicd_test"
            })
            if paramerror == '': #ok
                resp = {
                    "state":{
                        "ok":1,
                        "failed": ""
                    },
                    "neroll":{
                        "dbName":"",
                        "imageId":"",
                    },
                    "id":data['id'],
                    "search":[]
                }
            else: #failed
                resp = {
                    "state":{
                        "ok":0,
                        "failed": paramerror
                    },
                    "id":data['id'],
                    "search":[],
                    "enroll":{}
                }

        except BaseException as e:
            resp = {
                "state":{
                    "ok":0,
                    "failed": str(e)
                },
                "search":[],
                "enroll":{}
            }

        self.write(resp)
